package com.example.housekeeper.robotshousekeeper.secret;

import com.example.housekeeper.robotshousekeeper.utils.LogUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by k on 2017/8/17.
 */

public class Md5Utils {

        public static String sign(Map<String, String> map) {
            List<String> keyList = new ArrayList<String>();
            for (String key : map.keySet()) {
                if (key.subSequence(0, 1).equals("_") || key.contains("sign")
                        || key.contains("file")) {
                    continue;
                }
                keyList.add(key);
            }
            // 将所有参数按key的名称排序然后将对应value组成sign
            String[] keys = (String[]) keyList.toArray(new String[keyList.size()]);
            Arrays.sort(keys);
            String sign = "mykk#@!321";
            for (String key : keys) {
                Object value = map.get(key);
                if (value != null) {
                    sign += value.toString();
                }
            }
            // 为sign进行md5加密
            LogUtils.info("HttpUtils : ",sign);
            return MD5.str2MD5(sign);
        }

}
